package com.czd.support.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.czd.base.model.Paginate;
import com.czd.base.utils.WebUtils;
import com.czd.support.common.Configuration;
import com.czd.support.model.Manager;
import com.czd.support.model.Record;
import com.czd.support.service.RecordService;


@Controller
@RequestMapping(value="/record")
public class RecordController    extends  BaseController{
     
	@Autowired
	private  RecordService  recordService  ;
	
	/**
     * 列表页
     * @param model
     * @param request
     * @param answers
     * @return
     */
	@RequestMapping(value = {"/", "", "list"}, method = RequestMethod.GET)
	public String list(Record  record, HttpServletRequest request, Model model, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo) {
		Manager manager = this.getSesionUser(request);
		if(manager != null){
			record.setPageSize(Configuration.getInstance().getDefault_page_size());
			record.setPageNo(pageNo);
			String kw = WebUtils.findParamStr(request,"kw");
			System.out.println(kw);
			Paginate paginate = recordService.queryForPage(record , kw);
			model.addAttribute("paginate", paginate);
			return "record/list";
		}else{
			return "redirect:/login";
		}
		
	}
	
	@RequestMapping(value = "/{id}/details", method = RequestMethod.GET)
	public String details(@PathVariable int id, Model model){
		 //查出詳細數據
		Record record = recordService.findById(id);
		model.addAttribute("record", record);
		return "record/details";
	}
       
    
    
    
    
}
